package gdou.gym.exception;

import gdou.gym.returnvo.ResultVo;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SysException.class)
    public ResultVo handle(SysException e) {
        e.printError();
        return new ResultVo(e.getStateCode());
    }


    @ExceptionHandler(DataAccessException.class)
    public ResultVo update(DataAccessException e) {
        e.printStackTrace();
        return new ResultVo(StateCode.UPDATE_ERROR);
    }

    @ExceptionHandler({RuntimeException.class,})
    public ResultVo defalut(RuntimeException e) {
        if (e.getClass().getAnnotation(ResponseStatus.class) != null) throw e;
        e.printStackTrace();
        return new ResultVo(500, "出错了", null);
    }


}
